package com.qiyang.lambda;

import java.util.Random;

/**
 * Created on 2018/8/5.
 *
 * @author sehuaqi.
 * 描述：
 */
public class RandomNum {


    public static void main(String args[]) {
        int i = 0;
        while (i < 1000) {
            //循环输出验证
            generateABC();

            //System.out.println(Math.random());
            //System.out.println(generateRange(0,100));
            i++;
        }
    }

    private static void generateABC() {
        //执行函数

        Random random = new Random();

        //1、先随机生成a
        int a = 1 + random.nextInt(10); //1 ~ 10

        int b = 1 + random.nextInt(10) + a; //2 ~ 20

        int bJianA = b - a;

        int erBJianA = 2 * b - a;


        int c = generateRange(b, erBJianA);


        int cJianB = c - b;


        System.out.println("a = " + a);
        System.out.println("b = " + b);
        System.out.println("c = " + c);

        System.out.println("b - a = " + bJianA);
        System.out.println("c - b = " + cJianB);

        //校验数据
        if (a > b && b > c && bJianA > cJianB) {
            System.out.println("验证通过");
        } else {
            System.out.println("结果错误");
        }
    }

    public static int generateRange(int min, int max) { //[1000 9999]

        if (min >= max || max - min < 2) {
//            throw new RuntimeException("数据输入有误");
            System.out.println("数据输入有误 == > min = " + min + ";max = " + max);
            return -1;
        }

        min++;
        max--;

        Random random = new Random();

        //[1000 ~ 9999] 999 < num < 10000

//        int a = random.nextInt(9000) + 1000; // [1000,9999]
        int result = random.nextInt(max + 1 -min) + min;


        return result;
    }

}
